package com.hermes.biz.common.util.message;

import java.util.HashMap;
import java.util.Map;

import com.hermes.biz.common.model.message.PostMessageUnitDO;

/**
 *
 */
public class UserEventRepoUtil {

    public volatile static UserEventRepoUtil userEventRepoUtil;

    private Map<Long, PostMessageUnitDO>     userMessageMap;

    private UserEventRepoUtil() {
        userMessageMap = new HashMap<Long, PostMessageUnitDO>();
    }

    public static UserEventRepoUtil getUserEventMapUtil() {
        if (userEventRepoUtil == null) {
            synchronized (UserEventRepoUtil.class) {
                if (userEventRepoUtil == null) {
                    userEventRepoUtil = new UserEventRepoUtil();
                }
            }
        }
        return userEventRepoUtil;
    }

    public PostMessageUnitDO getIdNumInMap(long userId) {
        Object result = userMessageMap.get(userId);
        if (result != null) {
            return (PostMessageUnitDO) result;
        }
        return null;
    }

    @SuppressWarnings("unchecked")
    public HashMap<Long, PostMessageUnitDO> getUserMessageMap() {
        Object result = userMessageMap;
        if (result != null) {
            return (HashMap<Long, PostMessageUnitDO>) result;
        }
        return null;
    }

    public boolean putUserInfoToMap(long userId, PostMessageUnitDO messageDO) {

        userMessageMap.put(userId, messageDO);
        return true;

    }

}
